﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Controls.Primitives;

namespace HomeMediaBrowser
{
    /// <summary>
    /// Interaction logic for BitmapButton.xaml
    /// </summary>
    public partial class BitmapButton : Button
    {
        #region Dependency Properties
        public static readonly DependencyProperty NoramlBitmapProperty = DependencyProperty.Register("NoramlBitmap", typeof(ImageBrush), typeof(BitmapButton), new FrameworkPropertyMetadata());
        public static readonly DependencyProperty HightlightBitmapProperty = DependencyProperty.Register("HightlightBitmap", typeof(ImageBrush), typeof(BitmapButton), new FrameworkPropertyMetadata());
        public static readonly DependencyProperty SelectBitmapProperty = DependencyProperty.Register("SelectBitmap", typeof(ImageBrush), typeof(BitmapButton), new FrameworkPropertyMetadata());
        public static readonly DependencyProperty DisableBitmapProperty = DependencyProperty.Register("DisableBitmap", typeof(ImageBrush), typeof(BitmapButton), new FrameworkPropertyMetadata());

        public static readonly DependencyProperty UsePolyonBorderProperty = DependencyProperty.Register("UsePolyonBorder", typeof(bool), typeof(BitmapButton), new FrameworkPropertyMetadata(false));
        public static readonly DependencyProperty NotUsePolyonBorderProperty = DependencyProperty.Register("NotUsePolyonBorder", typeof(bool), typeof(BitmapButton), new FrameworkPropertyMetadata(true));
        public static readonly DependencyProperty PolyonBorderPointsProperty = DependencyProperty.Register("PolyonBorderPoints", typeof(PointCollection), typeof(BitmapButton), new FrameworkPropertyMetadata());


        public static readonly DependencyProperty BitmapButtonWidthProperty = DependencyProperty.Register("BitmapButtonWidth", typeof(double), typeof(BitmapButton), new FrameworkPropertyMetadata(14.0));
        public static readonly DependencyProperty BitmapButtonHeightProperty = DependencyProperty.Register("BitmapButtonHeight", typeof(double), typeof(BitmapButton), new FrameworkPropertyMetadata(14.0));

        #endregion

        #region Dependency Property backing CLR properties
        public ImageBrush NoramlBitmap
        {
            get { return (ImageBrush)GetValue(NoramlBitmapProperty); }
            set { SetValue(NoramlBitmapProperty, value); }
        }
        public ImageBrush HightlightBitmap
        {
            get { return (ImageBrush)GetValue(HightlightBitmapProperty); }
            set { SetValue(HightlightBitmapProperty, value); }
        }
        public ImageBrush SelectBitmap
        {
            get { return (ImageBrush)GetValue(SelectBitmapProperty); }
            set { SetValue(SelectBitmapProperty, value); }
        }
        public ImageBrush DisableBitmap
        {
            get { return (ImageBrush)GetValue(DisableBitmapProperty); }
            set { SetValue(DisableBitmapProperty, value); }
        }
        
        public bool UsePolyonBorder
        {
            get { return (bool)GetValue(UsePolyonBorderProperty); }
            set { SetValue(UsePolyonBorderProperty, value); }
        }
        public bool NotUsePolyonBorder
        {
            get { return (bool)GetValue(NotUsePolyonBorderProperty); }
            set { SetValue(NotUsePolyonBorderProperty, value); }
        }
        public PointCollection PolyonBorderPoints
        {
            get { return (PointCollection)GetValue(PolyonBorderPointsProperty); }
            set { SetValue(PolyonBorderPointsProperty, value); }
        }

        public double BitmapButtonWidth
        {
            get { return (double)GetValue(BitmapButtonWidthProperty); }
            set { SetValue(BitmapButtonWidthProperty, value); }
        }
        public double BitmapButtonHeight
        {
            get { return (double)GetValue(BitmapButtonHeightProperty); }
            set { SetValue(BitmapButtonHeightProperty, value); }
        }

        #endregion

        public BitmapButton()
        {
            InitializeComponent();
            AddHandler(System.Windows.Controls.Button.ClickEvent, new System.Windows.RoutedEventHandler(this.MouseClickHandler));
        }
        private void MouseClickHandler(object sender, RoutedEventArgs e)
        {
            OnClickButton();
        }
        public static RoutedEvent ClickButtonEvent = EventManager.RegisterRoutedEvent("ClickButton", RoutingStrategy.Bubble,
                typeof(RoutedEventHandler), typeof(BitmapButton));

        public event RoutedEventHandler ClickButton
        {
            add { AddHandler(ClickButtonEvent, value); }
            remove { RemoveHandler(ClickButtonEvent, value); }
        }

        protected virtual void OnClickButton()
        {
            RoutedEventArgs args = new RoutedEventArgs();
            args.RoutedEvent = ClickButtonEvent;
            args.Source = this;
            RaiseEvent(args);
        }

    }
}
